package com.mzxy.mztopline.adapter;

import android.os.Bundle;

import com.mzxy.mztopline.bean.NewsBean;
import com.mzxy.mztopline.fragment.AdBannerFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

public class AdBannerAdapter extends FragmentStatePagerAdapter {


    private List<NewsBean> abl;
    public AdBannerAdapter (FragmentManager fm) {
        super(fm);
        abl = new ArrayList<>();
    }

    /**
     *  设置数据更新界面
     */
    public void setData(List<NewsBean> abl) {
        this.abl = abl;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Bundle args = new Bundle();
        if (abl.size() > 0)
            args.putSerializable("ad", abl.get(position % abl.size()));
        return AdBannerFragment.newInstance(args);
    }

    @Override
    public int getCount() {
        return abl.size();
    }
}
